﻿using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using AutoPoco;
using AutoPoco.DataSources;
using AutoPoco.Engine;
using InvoiceProject.Controllers;
using InvoiceProject.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using InvoiceProject.Enums;
using Moq;

namespace InvoiceProject.Tests.AddressUnitTests
{


    /// <summary>
    ///This is a test class for BusinessTest and is intended
    ///to contain all BusinessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AddressTest
    {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

       

        [TestMethod()]
        public void AddressValid()
        {
           Address address = new Address();

            address.AddressLine1 = "4 TEST St";
            address.AddressLine2 = "Joe";
            address.PostCode = 1234;
            address.State = "ACT";
            address.Suburb = "Belconnen";

         //   address.UserCreated = "TestUser";
            address.UserModified = "ModUser";
          //  address.DateCreated = DateTime.Now;
            address.DateModified = DateTime.Now;

            Assert.IsTrue(address.IsValid());

        }


        [TestMethod()]
        [ExpectedException(typeof(ValidationException))]
        public void AddressInvalidStreetLine1()
        {
            Address address = new Address();
            address.AddressLine1 = "";
            address.AddressLine2 = "Joe";
            address.PostCode = 1234;
            address.State = "ACT";
            address.Suburb = "Belconnen";
          //  address.UserCreated = "TestUser";
            address.UserModified = "ModUser";
         //   address.DateCreated = DateTime.Now;
            address.DateModified = DateTime.Now;
            var validationContext = new ValidationContext(address, null, null);
            Validator.ValidateObject(address, validationContext);
       
       
        }

        [TestMethod()]
        [ExpectedException(typeof(ValidationException))]
        public void AddressInvalidState()
        {
            Address address = new Address();
            address.AddressLine1 = "AddressLine1";
            address.AddressLine2 = "Joe";
            address.PostCode = 1234;
            address.State = "";
            address.Suburb = "Belconnen";
         //   address.UserCreated = "TestUser";
            address.UserModified = "ModUser";
          //  address.DateCreated = DateTime.Now;
            address.DateModified = DateTime.Now;
            var validationContext = new ValidationContext(address, null, null);
            Validator.ValidateObject(address, validationContext);
        }


        [TestMethod()]
        public void AddressTestUpdateModelForSaveMethod()
        {
            Address address = new Address();
            address.AddressLine1 = "AddressLine1";
            address.AddressLine2 = "Joe";
            address.PostCode = 1234;
            address.State = "ACT";
            address.Suburb = "Belconnen";
            var validationContext = new ValidationContext(address, null, null);
            Validator.ValidateObject(address,validationContext);
        
        }
  

      
    }
}
